import { defineConfig } from "vite";
import postcssConfig from "./postcss.config";
import uni from "@dcloudio/vite-plugin-uni";
import uvtw from "@uni-helper/vite-plugin-uni-tailwind";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    postcss: postcssConfig,
  },
  plugins: [
    uvtw(),
    uni(),
    AutoImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/, // .vue
      ],
      imports: ["vue", "uni-app"],
      dts: "auto-imports.d.ts",
    }),
    Components({
      // relative paths to the directory to search for components.
      dirs: ["src/components"],

      // valid file extensions for components.
      extensions: ["vue"],
      // search for subdirectories
      deep: true,
      // resolvers for custom components
      resolvers: [], // AntDesignVueResolver()

      // generate `components.d.ts` global declarations,
      // also accepts a path for custom filename
      dts: "src/components/components.d.ts",

      // Allow subdirectories as namespace prefix for components.
      directoryAsNamespace: false,
      // Subdirectory paths for ignoring namespace prefixes
      // works when `directoryAsNamespace: true`
      globalNamespaces: [],

      // auto import for directives
      // default: `true` for Vue 3, `false` for Vue 2
      // Babel is needed to do the transformation for Vue 2, it's disabled by default for performance concerns.
      // To install Babel, run: `npm install -D @babel/parser @babel/traverse`
      directives: true,

      // filters for transforming targets
      include: [
        /\.vue$/,
        /\.vue\?vue/,
        /\.jsx$/,
        /\.jsx\?jsx/,
        /\.tsx$/,
        /\.tsx\?tsx/,
      ],
      exclude: [
        /[\\/]node_modules[\\/]/,
        /[\\/]\.git[\\/]/,
        /[\\/]\.nuxt[\\/]/,
      ],
    }),
  ],
});
